package org.devf.fork.imsimulator.socket.handler;

import cn.hutool.core.util.ReflectUtil;
import org.devf.fork.imsimulator.socket.Ihandler;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * MsgHandlerMgr related
 *
 * @author wanghuafu
 * @since 1.0  2023/9/12 16:43
 */
public class MsgHandlerFactory {


    private static final Map<String, Ihandler> instanceHandlers = new ConcurrentHashMap<>();


    /**
     * 聊天消息处理器
     *
     * @return 消息处理器
     */
    public static Ihandler ChatHandler() {
        Ihandler chatHandler = instanceHandlers.get(ChatHandler.class.getSimpleName());
        if (null == chatHandler) {
            chatHandler = new ChatHandler();
            instanceHandlers.put(ChatHandler.class.getSimpleName(), chatHandler);
            return chatHandler;
        }
        return chatHandler;
    }

    public static Ihandler ConnectHandler() {
        Ihandler connectHandler = instanceHandlers.get(ConnectHandler.class.getSimpleName());
        if (null == connectHandler) {
            connectHandler = new ConnectHandler();
            instanceHandlers.put(ConnectHandler.class.getSimpleName(), connectHandler);
            return connectHandler;
        }
        return connectHandler;
    }

    public static Ihandler HeartHandler() {
        Ihandler heartHandler = instanceHandlers.get(HeartHandler.class.getSimpleName());
        if (null == heartHandler) {
            heartHandler = new HeartHandler();
            instanceHandlers.put(HeartHandler.class.getSimpleName(), heartHandler);
            return heartHandler;
        }
        return heartHandler;
    }

    public static Ihandler FriendOnlineHandler() {
        Ihandler handler = instanceHandlers.get(FriendOnlineHandler.class.getSimpleName());
        if (null == handler) {
            handler = new FriendOnlineHandler();
            instanceHandlers.put(FriendOnlineHandler.class.getSimpleName(), handler);
            return handler;
        }
        return handler;
    }

    public static List<Ihandler> findHandlers() {
        ConnectHandler();
        HeartHandler();
        ChatHandler();
        FriendOnlineHandler();
        return new ArrayList<>(instanceHandlers.values());
    }



}
